package io.github.viscent.mtpattern.ch9.threadpool.example;

import io.github.viscent.util.Debug;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@SuppressWarnings("all")
public class ThreadPoolSize4IOIntensiveTask {

    public static void main(String[] args) {
        // 核心线程池大小为1、最大线程池大小为2*Ncpu
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(1, Runtime.getRuntime().availableProcessors() * 2, 60, TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(200));

        threadPool.submit(new IOIntensiveTask());
        threadPool.shutdown();
    }

    /**
     * 某个I/O密集型任务
     */
    private static class IOIntensiveTask implements Runnable {
        @Override
        public void run() {
            // 执行大量的I/O操作
            Debug.info("Running IO-intensive task...");
        }
    }

}
